package osiris;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import osiris.utils.OsirisStringUtils;

public class MenuItem {

		private MenuItem parent;
		private String text;
		private String action;
		private List<MenuItem> childs;		
		
		public MenuItem(){
		
			childs=new ArrayList<MenuItem>();	
		}
		
		public MenuItem(MenuItem parent){
			
			childs=new ArrayList<MenuItem>();	
			this.setParent(parent);
			
		}
		
		public MenuItem(MenuItem parent, String text){
			
			childs=new ArrayList<MenuItem>();	
			this.setParent(parent);
			this.setText(text);
			
		}
		
		public MenuItem(MenuItem parent, String text, String action){
			
			childs=new ArrayList<MenuItem>();	
			this.setParent(parent);
			this.setText(text);
			this.setAction(action);
		}
				
		public MenuItem getParent() {
			return parent;
		}
		
		public void setParent(MenuItem parent) {
			this.parent = parent;
		}
		
		public String getText() {
			return text;
		}
		
		public void setText(String text) {
			this.text = text;
		}
		
		public String getAction() {
			return action;
		}
		
		public void setAction(String action) {
			this.action = action;
		}
		
		public List<MenuItem> getChilds() {
			return childs;
		}
		
		public void add(MenuItem aChild) {
			childs.add(aChild);
		}
		
		public void printMenu(int level){
			
			Iterator<MenuItem> menu=childs.iterator();
			
			while (menu.hasNext()){
				MenuItem aMenu = menu.next();
				String spacesToAdd=OsirisStringUtils.padLeftWithSpaces (" ", (level*5));
				System.out.println(spacesToAdd+aMenu.getText());
				level ++;
				aMenu.printMenu(level);
				level --;
			}
			
			
		}
		
	
}
